--[[/**
-- * 
 * 所受伤害由目标代替我承受
 * [0] n 万分比
-- *
-- */]]

---@class BuffEffect603101 : BaseBuffEffect
BuffEffect603101 = ClientFight.CreateClass("BuffEffect603101", ClientFight.BaseBuffEffect)
local t = BuffEffect603101

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = {...};
    local buffEffectValue = buff.buffBean.f_BuffEffectValue;
    local calculatorType = buffEffectValue[1];
    local damageType = buffEffectValue[2];
    local calculateAttrType = buffEffectValue[3];
    local bonus = buffEffectValue[4] * buff.overlay;
    local modifiedRatio = buffEffectValue[5] * buff.overlay;
    local calculator = calculatorType == 0 and buff.source or buff.target;

    local fightTeam = fight.teams[3 - buff.source.teamIndex];
    local configDis = Utils.toRatio(buffEffectValue[6]);
    local fighters = clone(fightTeam.fighters);
    for k, target in pairs(fighters) do
        if (target:isDie()) then
            goto continue;
        end
        if (target:isSummons() and not target.isRealSummons()) then
            goto continue;
        end
        if (DistanceUtil.countDistance(buff.source.position, target.position) > configDis) then
            goto continue;
        end
        local result = AttackUtils.calculateEffectDamage(buff.source, target, damageType, calculator, calculateAttrType, modifiedRatio, bonus);
        if (result.damage <= 0) then
            SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff:"
                    .. buff.modelId .. " 触发反击伤害(被免疫了)，伤害值：" .. result.damage);
            goto continue;
        end
        DamageManager.realDamage(fight, buff.source, target, buff.modelId, result, damageType);
        --每伤害一个人,恢复自身生命
        local addHp = Utils.calcRatio(FighterAttributeManager.getFightAttr(buff.source, FighterAttributeEnum.HP), buffEffectValue[6]);
        DamageManager.setFighterHp(fight, buff.source, buff.source, null, DamageResultTypeEnum.HEAL, addHp, buff.source.hp + addHp, true, false, true);
        SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff:"
                .. buff.modelId .. " 触发反击伤害，伤害值：" .. result.damage .. " 自身恢复生命: " .. addHp);
        :: continue ::
    end
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

t.New()